/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package entity;

import java.io.Serializable;
import java.sql.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.transaction.UserTransaction;
import javax.validation.constraints.NotNull;

/**
 *
 * @author Marco
 */
@Entity
@NamedQueries({
    @NamedQuery(name = "Evento.findAll", query = "SELECT e FROM Evento e"),
    @NamedQuery(name = "Evento.findByID", query = "SELECT e FROM Evento e WHERE e.id = :id"),
    @NamedQuery(name = "Evento.findExist", query = "SELECT e FROM Evento e WHERE e.dataEvento = :dataevento AND e.orari = :ora"),
})
public class Evento implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "ID")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String titoloEvento;
    @Column(length=1000)
    private String descrizioneEvento;
    private String orari;
    private float prezzoArancio;
    private float prezzoBlu;
    private float prezzoRosso;
    private float prezzoVerde;
    private float prezzoGiallo;
    private float prezzoParterre;
    private String locandina;
    private Date dataEvento;

    /**
     * Get the value of dataEvento
     *
     * @return the value of dataEvento
     */
    public Date getDataEvento() {
        return dataEvento;
    }

    /**
     * Set the value of dataEvento
     *
     * @param dataEvento new value of dataEvento
     */
    public void setDataEvento(Date dataEvento) {
        this.dataEvento = dataEvento;
    }

    

    


    
    
    /**
     * Get the value of titoloEvento
     *
     * @return the value of titoloEvento
     */
    public String getTitoloEvento() {
        return titoloEvento;
    }

    /**
     * Set the value of titoloEvento
     *
     * @param titoloEvento new value of titoloEvento
     */
    public void setTitoloEvento(String titoloEvento) {
        this.titoloEvento = titoloEvento;
    }
    
    /**
     * Get the value of locandina
     *
     * @return the value of locandina
     */
    public String getLocandina() {
        return locandina;
    }

    /**
     * Set the value of locandina
     *
     * @param locandina new value of locandina
     */
    public void setLocandina(String locandina) {
        this.locandina = locandina;
    }


    /**
     * Get the value of prezzoParterre
     *
     * @return the value of prezzoParterre
     */
    public float getPrezzoParterre() {
        return prezzoParterre;
    }

    /**
     * Set the value of prezzoParterre
     *
     * @param prezzoParterre new value of prezzoParterre
     */
    public void setPrezzoParterre(float prezzoParterre) {
        this.prezzoParterre = prezzoParterre;
    }


    /**
     * Get the value of prezzoGiallo
     *
     * @return the value of prezzoGiallo
     */
    public float getPrezzoGiallo() {
        return prezzoGiallo;
    }

    /**
     * Set the value of prezzoGiallo
     *
     * @param prezzoGiallo new value of prezzoGiallo
     */
    public void setPrezzoGiallo(float prezzoGiallo) {
        this.prezzoGiallo = prezzoGiallo;
    }


    /**
     * Get the value of prezzoVerde
     *
     * @return the value of prezzoVerde
     */
    public float getPrezzoVerde() {
        return prezzoVerde;
    }

    /**
     * Set the value of prezzoVerde
     *
     * @param prezzoVerde new value of prezzoVerde
     */
    public void setPrezzoVerde(float prezzoVerde) {
        this.prezzoVerde = prezzoVerde;
    }


    /**
     * Get the value of prezzoRosso
     *
     * @return the value of prezzoRosso
     */
    public float getPrezzoRosso() {
        return prezzoRosso;
    }

    /**
     * Set the value of prezzoRosso
     *
     * @param prezzoRosso new value of prezzoRosso
     */
    public void setPrezzoRosso(float prezzoRosso) {
        this.prezzoRosso = prezzoRosso;
    }

    

    /**
     * Get the value of prezzoBlu
     *
     * @return the value of prezzoBlu
     */
    public float getPrezzoBlu() {
        return prezzoBlu;
    }

    /**
     * Set the value of prezzoBlu
     *
     * @param prezzoBlu new value of prezzoBlu
     */
    public void setPrezzoBlu(float prezzoBlu) {
        this.prezzoBlu = prezzoBlu;
    }


    /**
     * Get the value of prezzoArancio
     *
     * @return the value of prezzoArancio
     */
    public float getPrezzoArancio() {
        return prezzoArancio;
    }

    /**
     * Set the value of prezzoArancio
     *
     * @param prezzoArancio new value of prezzoArancio
     */
    public void setPrezzoArancio(float prezzoArancio) {
        this.prezzoArancio = prezzoArancio;
    }


    /**
     * Get the value of orari
     *
     * @return the value of orari
     */
    public String getOrari() {
        return orari;
    }

    /**
     * Set the value of orari
     *
     * @param orari new value of orari
     */
    public void setOrari(String orari) {
        this.orari = orari;
    }


    /**
     * Get the value of descrizioneEvento
     *
     * @return the value of descrizioneEvento
     */
    public String getDescrizioneEvento() {
        return descrizioneEvento;
    }

    /**
     * Set the value of descrizioneEvento
     *
     * @param descrizioneEvento new value of descrizioneEvento
     */
    public void setDescrizioneEvento(String descrizioneEvento) {
        this.descrizioneEvento = descrizioneEvento;
    }


    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Evento)) {
            return false;
        }
        Evento other = (Evento) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Evento[ id=" + id + " ]";
    }

    public void persist(Object object) {
        /* Add this to the deployment descriptor of this module (e.g. web.xml, ejb-jar.xml):
         * <persistence-context-ref>
         * <persistence-context-ref-name>persistence/LogicalName</persistence-context-ref-name>
         * <persistence-unit-name>CentroSportivo-ejbPU</persistence-unit-name>
         * </persistence-context-ref>
         * <resource-ref>
         * <res-ref-name>UserTransaction</res-ref-name>
         * <res-type>javax.transaction.UserTransaction</res-type>
         * <res-auth>Container</res-auth>
         * </resource-ref> */
        try {
            Context ctx = new InitialContext();
            UserTransaction utx = (UserTransaction) ctx.lookup("java:comp/env/UserTransaction");
            utx.begin();
            EntityManager em = (EntityManager) ctx.lookup("java:comp/env/persistence/LogicalName");
            em.persist(object);
            utx.commit();
        } catch (Exception e) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", e);
            throw new RuntimeException(e);
        }
    }
    
}
